package jun.home.dailycost.dao.impl;

import java.util.List;

import jun.home.dailycost.dao.CategoryDao;
import jun.home.dailycost.domain.Category;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository("categoryDao")
public class CategoryDaoImpl implements CategoryDao {

	private SessionFactory sf;
	
	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sf = sessionFactory;
	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional(readOnly = true)
	public List<Category> selectAll() {
		return sf.getCurrentSession().createQuery("from Category").list();
	}

	@Override
	@Transactional(readOnly = true)
	public Category selectByCid(int cid) {
		return (Category) sf.getCurrentSession().get(Category.class, cid);
	}

	@Override
	@Transactional
	public void store(Category cat) {
		sf.getCurrentSession().saveOrUpdate(cat);
	}

	@Override
	@Transactional
	public void delete(Category cat) {
		sf.getCurrentSession().delete(cat);
	}
	
	

}
